// pagesWorkOrderSearchFilter/pagesWorkOrderSearchFilter.js
import {
  SUB_PAGES
} from "../../config/router.config";
import {
  createStoreBindings
} from "mobx-miniprogram-bindings";
import {
  handleDelChecked,
  handleFilterRouter
} from "../../utils/util";
import {
  workOrderReviewIndexFilterStore
} from "../../store/workOrderReviewIndexFilterStore";
import {
  deptSelectStore
} from "../../store/deptSelectStore";
import {
  userSelectStore
} from "../../store/userSelectStore";
import {
  DIC_KEY
} from "../../config/dicKey.config";
import {
  dicSelectStore
} from "../../store/dicSelectStore";


Page({
  /**
   * 页面的初始数据
   */
  data: {
    deptData: [],
    userData: [],
    deptGroupUserData: [],
    dicFaultClass: [],

  },

  // 报修科室
  onFilterDept() {
    wx.navigateTo({
      url: `${SUB_PAGES.Filter.FILTER_DEPT_SELECT.router}?${handleFilterRouter(SUB_PAGES.WorkOrder.WORK_ORDER_REVIEW_INDEX_FILTER.router,'selectDept','workOrderReviewIndexFilterDeptValue')}`,
    })
  },
  //建单人
  onFilterUser() {
    wx.navigateTo({
      url: `${SUB_PAGES.Filter.FILTER_USER_SELECT.router}?${handleFilterRouter(SUB_PAGES.WorkOrder.WORK_ORDER_REVIEW_INDEX_FILTER.router,'','workOrderReviewIndexFilterBuildValue')}`,
    })
  },
  // 处理科室/小组/人
  onFilterDepGroupUser() {
    wx.navigateTo({
      url: `${SUB_PAGES.Filter.FILTER_DEPT_SELECT.router}?${handleFilterRouter(SUB_PAGES.WorkOrder.WORK_ORDER_REVIEW_INDEX_FILTER.router,'selectDeptGroupUser','workOrderReviewIndexFilterDeptTeamUserValue')}`,
    })
  },
  // 故障分类
  onFilterDicFault() {
    wx.navigateTo({
      url: `${SUB_PAGES.Filter.FILTER_DIC_SELECT.router}?${handleFilterRouter(SUB_PAGES.WorkOrder.WORK_ORDER_REVIEW_INDEX_FILTER.router,'','workOrderReviewIndexFilterFaultValue',DIC_KEY.obs_fault_type)}`,
    })
  },

  // 删除报修科室选择数据
  onDelDeptData(event) {
    const {
      value
    } = event.currentTarget.dataset
    const data = handleDelChecked(value, this.data.deptData)
    app_setData(AppGlobalDataKey.SelectedDeptData, data)
    this.setData({
      deptData: data
    })
  },

  // 报修时间
  onChangeRepairTime({
    detail
  }) {
    const {
      value
    } = detail
    this.setRepairDate(value)

  },
  // 完成时间
  onCompleteTime({
    detail
  }) {
    const {
      value
    } = detail
    console.log(value, 'value');
    this.setCompleteDate(value)
  },

  // 提交
  onSubmit() {
    console.log(this.data.workOrderReviewIndexFilterDeptTeamUserValue, 'workOrderReviewIndexFilterDeptTeamUserValue');
    this.setDepTeamUser(this.data.workOrderReviewIndexFilterDeptTeamUserValue)
    this.setBuildIdList(this.data.workOrderReviewIndexFilterBuildValue)
    this.setDeptIdList(this.data.workOrderReviewIndexFilterDeptValue)
    this.setFaultTypeList(this.data.workOrderReviewIndexFilterFaultValue)
    wx.redirectTo({
      url: SUB_PAGES.WorkOrder.WORK_ORDER_REVIEW_INDEX.router,
    })
  },
  // 重置
  onReset() {
    this.workOrderReviewIndexFilterStoreReset()
    this.deptSelectStoreReset('workOrderReviewIndexFilterDeptTeamUserValue')
    this.deptSelectStoreReset('workOrderReviewIndexFilterDeptValue')

    this.setUserSelectStore('workOrderReviewIndexFilterBuildValue')
    this.dicSelectStoreReset('workOrderReviewIndexFilterFaultValue')



  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.storeBindings = createStoreBindings(this, {
      store: workOrderReviewIndexFilterStore,
      fields: ['buildIdList', 'completeEndTime', 'completeStartTime', 'deptIdList', 'faultTypeList', 'keywords', 'makeDeptIdList', 'makeTeamIdList', 'makeUserIdList', 'repairEndTime', 'repairStartTime', ],
      actions: ["setRepairDate", "setCompleteDate", "setDeptIdList", "setBuildIdList", "setDepTeamUser", "setFaultTypeList", "workOrderReviewIndexFilterStoreReset"],
    });
    this.storeBindings1 = createStoreBindings(this, {
      store: deptSelectStore,
      fields: ['workOrderReviewIndexFilterDeptValue', 'workOrderReviewIndexFilterDeptTeamUserValue'],
      actions: ['deptSelectStoreReset']
    });
    this.storeBindings2 = createStoreBindings(this, {
      store: userSelectStore,
      fields: ['workOrderReviewIndexFilterBuildValue'],
      actions: ['setUserSelectStore']
    });
    this.storeBindings3 = createStoreBindings(this, {
      store: dicSelectStore,
      fields: ['workOrderReviewIndexFilterFaultValue'],
      actions: ['dicSelectStoreReset']
    });

    this.storeBindings.updateStoreBindings()
    this.storeBindings1.updateStoreBindings()
    this.storeBindings2.updateStoreBindings()
    this.storeBindings3.updateStoreBindings()


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    this.storeBindings.destroyStoreBindings()
    this.storeBindings1.destroyStoreBindings()
    this.storeBindings2.destroyStoreBindings()
    this.storeBindings3.destroyStoreBindings()


  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})